var nowTime = document.getElementById('nowTime');
var ssje = document.getElementById('ssje');
var buqk = document.getElementById('buqk');
var bcqk = document.getElementById('bcqk');
var bcfy = document.getElementById('bcfy');
var documentNumber = document.getElementById('documentNumber');
var money_all = 0;
var hjys_money = 0;
var ssje_money = 0;
var buqk_money = 0;
var bcqk_money = 0;
var operationTime = document.getElementById("operationTime").value;
var abbreviation = document.getElementById("abbreviation").value;
var reservationsId = document.getElementById("reservationsId").value;
var getTime = document.getElementById("getTime").value;
var rechargeTime = document.getElementById("rechargeTime").value;
if (operationTime != null) {
    nowTime.innerText = rechargeTime.substring(0, 19);
} else {
    nowTime.innerText = getNowFormatDate();
}

function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + " " + date.getHours() + seperator2 + date.getMinutes()
        + seperator2 + date.getSeconds();
    return currentdate;
};
$.ajax({
    url: Feng.ctxPath + "/consultant/getOpenPrint",
    type: "post",
    data: {
        "operationTime": operationTime,
        "reservationsId": reservationsId,
        "abbreviation": abbreviation,
        "getTime": getTime,
    },
    success: function (data) {
        var arr = data;
        var plan_box = document.getElementById('plan_box');
        for (var i = 0; i < arr.length; i++) {
            var plan_child = document.createElement('div');
            if (arr[i].payServiceName == null || arr[i].payServiceName == "") {
                var str = " ";
                plan_child.innerHTML = str;
                plan_box.appendChild(plan_child);
                money_all += 0.00;
                hjys_money += 0.00;
                bcqk_money += 0.00;
                ssje_money += 0.00;
                buqk_money += 0.00;
            } else {
                var str = '<div style="display: flex;height: 22px;line-height: 22px;margin-top: 5px;">' +
                    '<div style="flex: 3;text-indent: 1.2em;" id="disposal">' + arr[i].payServiceName + '</div>' +
                    '<div style="flex: 1;text-align: center" id="number">' + arr[i].payServiceNum + '</div>' +
                    '<div style="flex: 1;text-align: center" id="price">' + arr[i].payService + '</div>' +
                    '<div style="flex: 1;text-align: center" id="orderDiscount">' + arr[i].orderDiscount + '</div>' +
                    '<div style="flex: 1;text-align: center" id="amount">' + parseFloat(arr[i].serviceActualPay+arr[i].depositAmount)+'</div>' +
                    '</div>';
                plan_child.innerHTML = str;
                plan_box.appendChild(plan_child);
                money_all += parseFloat(arr[i].foldingPay);
                ssje_money += parseFloat(arr[i].serviceActualPay+arr[i].depositAmount);
                buqk_money += parseFloat(arr[i].serviceActualPay+arr[i].depositAmount);
                bcqk_money = parseFloat(arr[i].sumarrears);
                hjys_money += parseFloat(arr[i].foldingPay);
            }
        }
        if($("#isDoValue").val() != '4') {
            bcfy.innerText = money_all.toFixed(2);
        }else{
            bcfy.innerText = ssje_money.toFixed(2);
        }
        buqk.innerText = buqk_money.toFixed(2);
        ssje.innerText = ssje_money.toFixed(2);
        bcqk.innerText = bcqk_money.toFixed(2);
        if (hjys_money < ssje_money) {
            bcfy.innerText = ssje_money.toFixed(2);
        }
        documentNumber.innerText = data[0].documentNumber;
        if($("#isDoValue").val() != '3'){
            $("#arrearsFather").hide();
        }
    },
    error: function (data) {
        alert('没有权限，请联系系统管理员!');
        parent.layer.close(parent.layer.getFrameIndex(window.name));
    }
});

var bt = document.getElementById("bt");
var div_print = document.getElementById("div_print");
$("#bt").click(function () {//打印代码
    printdiv(div_print);
    if (window.parent.$("#isDorj").val() == 'jz') {
        parent.layer.close(parent.layer.getFrameIndex(window.name))
    } else if (window.parent.$("#isDorj").val() == 'dd') {
        window.parent.location.reload();
        parent.layer.close(parent.layer.getFrameIndex(window.name));
    }
});

$("#cancel").click(function () {
    if (window.parent.$("#isDorj").val() == 'jz') {
        parent.layer.close(parent.layer.getFrameIndex(window.name))
    } else if (window.parent.$("#isDorj").val() == 'dd') {
        window.parent.location.reload();
        parent.layer.close(parent.layer.getFrameIndex(window.name));
    } else {
        parent.layer.close(parent.layer.getFrameIndex(window.name));
    }
});

function printdiv(printpage) {
    var newstr = printpage.innerHTML;
    var oldstr = document.body.innerHTML;
    document.body.innerHTML = newstr;
    window.print();
    document.body.innerHTML = oldstr;
    return false;
}